<?php
//20090211
//save in db



	// getting supported langauges from database
	$supportedlangs = array();
	$query        = "SELECT `lang`,`text` from `text` where `type`='txt_lang'";
	$result = mysql_query($query);
	$nr = mysql_num_rows($result);
	//while ($i < $nr) array_push($supportedlangs,mysql_result($result,$i++));
	while ($r=mysql_fetch_array($result)) array_push($supportedlangs,$r);


//	$supportedlangs = array("en","nl","de","sv","li","es","nb"); //?? get info from db??? 




// check and validy for $_REQUST (POST/GET/COOKIE)
	if (isset($_REQUEST['lang'])) {
		if (isset($_GET['lang'])) $reqlang = $_GET['lang']; else 
		if (isset($_POST['lang'])) $reqlang = $_POST['lang']; else $reqlang = $_COOKIE['lang'];
		foreach($supportedlangs as $supportedlang) {		
			if (!strcmp($reqlang,	$supportedlang[0])) {
				$lang = $reqlang;
				if (isset($_GET['lang'])) setcookie("lang","$lang"); 
				if (isset($_POST['lang'])) setcookie("lang","$lang");
				$updatelangdb = true;
				break;
			}	
		} 
	} 



// else look at browser request
	if (!isset($lang))	{
		$browserlangs = explode (",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
		foreach($browserlangs as $browserlang ) { 
			foreach($supportedlangs as $supportedlang) {		
				if (!strncmp($browserlang,	$supportedlang[0],2)) {
					$lang = $supportedlang[0];
					break;
				}	
			}
			if ($lang) break;
		}
		setcookie("lang","$lang");
	} 

if (!isset($lang)) $lang = "en";  

$SITE_FOOTER 			.= "  -  <a href=\"/index.php?do=terms\">".GetLangString($lang,"txt_terms")."</a>  --  ".GetLangString($lang,"txt_trans");
$TXT_CHAT = "Chat";
$SITE_LANG = "<form action=\"index.php\" method=\"post\"><select name=\"lang\" size=\"1\">";
	foreach($supportedlangs as $supportedlang) {
		$SITE_LANG .= "<option value=\"$supportedlang[0]\"";
		if ($supportedlang[0] == $lang) $SITE_LANG .= " selected";
		$SITE_LANG .=">$supportedlang[1]</option>";
	}
$SITE_LANG .="</select><br><input type=\"submit\" value=\"".GetLangString($lang,"txt_changelang")."\"></form>";




?>
